package fun.chutianshu;

public class Main {

    public static void main(String[] args) {
	// write your code here
        Outer outer = new Outer("Nested"); // 实例化一个Outer
        Outer.Inner inner = outer.new Inner("小白"); // 实例化一个Inner
        inner.hello();
        inner.hi();

        //下面异步内部匿名类使用
        Outer1 outer1 = new Outer1("小红");
        outer1.asyncHello();

    }
}


class Outer {
    private String name;

    Outer(String name) {
        this.name = name;
    }

    class Inner {
        private String name;

        Inner(String name){
            this.name = name;
        }
        Inner(){}
        void hello() {
            System.out.println("Hello, " + Outer.this.name);
        }
        void hi(){
            System.out.println("Hi,"+this.name);
        }
    }
}

class Outer1 {
    private String name;

    Outer1(String name) {
        this.name = name;
    }

    void asyncHello() {
        Runnable r = new Runnable() {
            @Override
            public void run() {
                System.out.println("Hello, " + Outer1.this.name);
            }
        };
        new Thread(r).start();
    }
    /*
     class Inner implements Runnable{
        @Override
            public void run() {
                System.out.println("Hello, " + Outer1.this.name);
            }
     }

     */
}
